package com.tjvib.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tjvib.R;

public class DataXyz extends RelativeLayout {

    private TextView data_xyz_tv_tit;
    private CheckBox data_xyz_cb_x, data_xyz_cb_y, data_xyz_cb_z;

    public void setTitle(String tit) {
        data_xyz_tv_tit.setText(tit);
    }

    public boolean x_isChecked() {
        return data_xyz_cb_x.isChecked();
    }

    public boolean y_isChecked() {
        return data_xyz_cb_y.isChecked();
    }

    public boolean z_isChecked() {
        return data_xyz_cb_z.isChecked();
    }

    public DataXyz(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
        initAttrs(context, attrs);
    }

    private void initView(Context context) {
        LayoutInflater.from(context).inflate(R.layout.data_xyz, this);

        data_xyz_tv_tit = findViewById(R.id.data_xyz_tv_tit);
        data_xyz_tv_tit.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);

        data_xyz_cb_x = findViewById(R.id.data_xyz_cb_x);
        data_xyz_cb_y = findViewById(R.id.data_xyz_cb_y);
        data_xyz_cb_z = findViewById(R.id.data_xyz_cb_z);
    }

    private void initAttrs(Context context, AttributeSet attrs) {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DataXyz);
        data_xyz_tv_tit.setText(typedArray.getString(R.styleable.DataXyz_xyz_tit));
        data_xyz_cb_x.setText(typedArray.getString(R.styleable.DataXyz_x_name));
        data_xyz_cb_y.setText(typedArray.getString(R.styleable.DataXyz_y_name));
        data_xyz_cb_z.setText(typedArray.getString(R.styleable.DataXyz_z_name));
    }
}
